<?php
/**
 * Created by PhpStorm.
 * User: zhouke
 * Date: 2018-09-12
 * Time: 15:49
 */

defined('BASEPATH') OR exit('No direct script access allowed');
class Passport extends CI_Controller {
    function __construct() {
        parent::__construct();
    }
    public function index() {
        $this->load->view ( 'admin/passport_in' );
    }
    public function in() {
        cache_clean();
        $ret = array( 'status' => false, 'info' => 'Error' );
        $this->form_validation->set_rules ( 'mobile', '', 'trim|required|xss_clean');
        $this->form_validation->set_rules ( 'password', '', 'trim|required|xss_clean');
        if( $this->form_validation->run() ) {
            $mobile = get_parameter('mobile');
            $password = get_parameter('password');
            $user = user_mobile_get($mobile);
            if ($user) {
                if ($user['password'] == md5($password)) {
                    user_login($user);
                    $ret['status'] = 1;
                    $ret['info'] = '登录成功';
                    $ret['url'] = site_url('admin/home');
                } else {
                    $ret['info'] ='密码错误';
                }
            } else {
                $ret['info'] = '手机号码错误';
            }
        } else {
            $ret['info'] = form_error('mobile').form_error('password');
        }
        json_out($ret);
    }
}